# -*- coding: utf-8 -*-
"""
@Time    : 2024/8/28 15:06 
@Author  : ZhangShenao 
@File    : chat_completion_api.py 
@Desc    : 调用OpenAI的Chat Completion API

API文档: https://platform.openai.com/docs/api-reference/chat/create
"""
import os

import dotenv
from openai import OpenAI

# 加载环境变量
dotenv.load_dotenv()

# 创建OpenAI客户端
client = OpenAI(base_url=os.getenv("OPENAI_API_BASE"))

completion = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
)

print(completion.choices[0].message)
